package com.litchishell.easy;

/**
 * @author LitchiShell
 * @description: 题目101：对称二叉树
 * @create 2022-09-03
 */
public class Solution021 {

    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return false;
        }
        return isSameTree(root.left, root.right);
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.right) && isSameTree(p.right, q.left);
        }
    }
}
